import * as user from '@/api/user.js'
import * as index from '@/api/index.js'
import * as resume from '@/api/resume.js'
import {
	mapMutations
} from 'vuex';
export default {

	data() {
		return {
			dqTiem: '', //会员到期时间
			resume_forward: '', //转发次数
			my_fx: '', //转发背景图
			title: '', //分享标题
			imgage: '', //分享图片
			lookNum: 0,
			Type: uni.getStorageSync('Type') || 0,
			userInfo: {
				"member_id": '',
				"head": "/static/user/head-pimg.png",
				"name": "",
				"gender": "",
				"date": '',
				"phone": "",
				"drving": '',
				"age": '',
				"txt": "",
				"type_ids": "",
				"salary_id": '',
				"salary_min": '',
				"salary_max": '',
				"areas_id": '',
				"areas_pid": '',
				"type": '',
				"state": '',
				"is_hide": '',
				"is_closure": '',
				"date_text": '',
				"date_date": '',
				"drving_text": '',
				"age_text": '',
				"areas_text": '',
				"areas_text_p": '',
				"type_text": [],
				"salary": ""
			}, //用户信息
			data0List: [{
					url: '/pages/news/index',
					name: '沟通过',
					value: '0',
					redirect: true
				},
				{
					url: '/pages/user/collect/index',
					name: '收藏',
					value: '0',
					redirect: false
				},
				{
					url: '/pages/user/record/index',
					name: '浏览记录',
					value: '0',
					redirect: false
				},
			], //接单
			card0List: [{
					url: '',
					title: '刷新接单',
					value: '提升接单活跃',
					image: '/static/user/refresh.png',
				},
				{
					url: '/pages/resume/index',
					title: '完善接单',
					value: '让需求找你',
					image: '/static/user/datum.png',
					redirect: true
				}
			], //接单
			naviga0List: [
				// {
				// 	url: '/pages/user/record/index',
				// 	value: '浏览记录',
				// 	image: '/static/user/icon/browse-icon.png',
				// 	redirect: false
				// },
				{
					url: '/pages/user/shield/index',
					value: '屏蔽雇主',
					image: '/static/user/icon/qi-icon.png',
					redirect: false
				}, {
					url: '',
					value: '电话屏蔽中',
					image: '/static/user/icon/hide-icon.png',
					redirect: false
				}, {
					url: '',
					value: '接单屏蔽中',
					image: '/static/user/icon/hide-icon.png',
					redirect: false
				}, {
					url: '/pages/user/service/index',
					value: '联系客服',
					image: '/static/user/icon/service-icon.png',
					redirect: false
				}, {
					url: '/pages/user/feedback/index',
					value: '我要反馈',
					image: '/static/user/icon/share-icon.png',
					redirect: false
				}, {
					url: '/pages/user/setting/index',
					value: '系统设置',
					image: '/static/user/icon/set-icon.png',
					redirect: false
				},
				{
					url: '/pages/user/cut/index',
					value: '切换身份',
					image: '/static/user/icon/cut-icon.png',
					redirect: false
				}
			], //接单
			data1List: [{
					url: '/pages/news/index',
					name: '沟通过',
					value: '0',
					redirect: true
				},
				{
					url: '/pages/user/collect/index',
					name: '收藏',
					value: '0',
					redirect: false
				},
				{
					url: '/pages/user/lookmy/index',
					name: '谁看过我',
					value: '0',
					redirect: false
				}
			], //需求
			card1List: [{
					url: '/pages/resume/index',
					title: '刷新需求',
					value: '提升需求曝光',
					image: '/static/user/refresh.png',
					redirect: true
				},
				{
					url: '/pages/user/datumh/index',
					title: '完善资料',
					value: '提高转化率',
					image: '/static/user/datum.png',
					redirect: false
				}
			], //需求
			naviga1List: [{
				url: '/pages/resume/index',
				value: '需求管理',
				image: '/static/user/icon/position-icon.png',
				redirect: true
			}, {
				url: '/pages/user/record/index',
				value: '浏览记录',
				image: '/static/user/icon/browse-icon.png',
				redirect: false
			}, {
				url: '/pages/user/code/index',
				value: '需求海报',
				image: '/static/user/icon/code-icon.png',
				redirect: false
			}, {
				url: '/pages/user/service/index',
				value: '联系客服',
				image: '/static/user/icon/service-icon.png',
				redirect: false
			}, {
				url: '/pages/user/feedback/index',
				value: '我要反馈',
				image: '/static/user/icon/feedback-icon.png',
				redirect: false
			}, {
				url: '/pages/user/setting/index',
				value: '系统设置',
				image: '/static/user/icon/set-icon.png',
				redirect: false
			}, {
				url: '',
				value: '推荐朋友',
				image: '/static/user/icon/share-icon.png',
				redirect: false
			}, 
			{
				url: '/pages/user/cut/index',
				value: '切换身份',
				image: '/static/user/icon/cut-icon.png',
				redirect: false
			},
			], //需求
		}
	},
	onShow() {
		if (uni.getStorageSync('Type') == 0) {
			this.data0List[0].value = this.$store.state.conversations.length
		} else {
			this.lookMy()
			this.data1List[0].value = this.$store.state.conversations.length
		}
		this.Type = uni.getStorageSync('Type')
		if (uni.getStorageSync('token')) {
			this.getUserInfo()
			// 收藏
			this.getCollectList()
			// 浏览记录
			this.getBrowseList()

		} else {
			this.userInfo = {}
		}
		// 获取分享信息
		this.nameGetConfig()
	},
	onLoad() {
		uni.$on('Type', (data) => {
			this.Type = uni.getStorageSync('Type')
			if (uni.getStorageSync('token')) {
				this.getUserInfo()
			}
			this.$tools.change(uni.getStorageSync('Type'))
		})
	},
	watch: {
		userInfo() {
			if (this.userInfo.is_hide == 1) {
				this.naviga0List[1].value = '电话屏蔽中'
				this.naviga0List[1].image = '/static/user/icon/hide-icon.png'
			} else {
				this.naviga0List[1].value = '电话展示中'
				this.naviga0List[1].image = '/static/user/icon/my-icon4.png'
			}
			if (this.userInfo.is_closure == 1) {
				this.naviga0List[2].value = '接单屏蔽中'
				this.naviga0List[2].image = '/static/user/icon/hide-icon.png'
			} else {
				this.naviga0List[2].value = '接单展示中'
				this.naviga0List[2].image = '/static/user/icon/my-icon4.png'
			}
		}
	},
	onShareAppMessage(res) {
		if (res.from === 'button') { // 来自页面内分享按钮
			if (uni.getStorageSync('token')) {
				user.wxForwardGetAward({
					type: 0
				}).then(res => {
					uni.setStorageSync('shareType', '1');
				})
			}

		}
		return {
			title: this.title, //分享标题
			imageUrl: this.imgage,
			path: '/pages/home/index'
		}
	},
	methods: {
		...mapMutations(['converList']),
		// App分享按钮
		shareBnt() {
			uni.share({
				provider: 'weixin',
				scene: "WXSceneSession",
				type: 5,
				// imageUrl: this.share.image,
				imageUrl: 'https://xczp.wanhedashuju.com/uploads/20220107/125c54dad49a1c68b2796dd71128f698.png',
				title: '县城直聘',
				miniProgram: {
			 	id: 'gh_6b4bd9a933d2',
					path: '/pages/user/index',
					type: 0,
					webUrl: 'https://app.wanhedashuju.com/'
				},
				success: ret => {
					user.wxForwardGetAward({
						type: 0
					}).then(res => {
						uni.setStorageSync('shareType', '1');
						this.getUserInfo()
					})
				}
			});
		},
		// 获取分享图片
		nameGetConfig() {
			index.nameGetConfig({
				name: 'wx_share_image,wx_share_title,my_fx,resume_forward'
			}).then(res => {
				this.imgage = res.data.wx_share_image
				this.title = res.data.wx_share_title
				this.my_fx = res.data.my_fx
				this.resume_forward = res.data.resume_forward
				if (uni.getStorageSync('shareType') == 1) {
					uni.showToast({
						icon: 'none',
						title: `查看需求已+${res.data.resume_forward}条,\n感谢您助力鱼台就业。`,
						duration: 2000
					});
					uni.removeStorageSync('shareType');
				}
			})
		},
		// 开通会员
		vipBnt() {
			if (uni.getStorageSync('token')) {
				this.$tools.navigate('/pages/user/vip/index')
			} else {
				this.$tools.toast('请登录')
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/login/index'
					})
				}, 1000)
			}
		},
		// 跳转到完善个人信息页面
		datumhbnt() {
			if (uni.getStorageSync('token')) {
				let type = uni.getStorageSync('Type')
				if (type == 0) {
					this.$tools.navigate('/pages/user/myDatumh/index')
				} else {
					this.$tools.navigate('/pages/user/datumh/index')
				}
			} else {
				this.$tools.toast('请登录')
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/login/index'
					})
				}, 1000)
			}

		},
		// 获取用户信息
		getUserInfo() {
			user.getUserInfo({
				type: this.Type
			}).then(res => {
				this.userInfo = res.data
				if (this.Type == '1') {
					this.lookNum = res.data.visual_upper_limit - res.data.company_resume
				} else {
					this.lookNum = res.data.visual_upper_limit - res.data.resume_position
				}
				uni.setStorage({
					key: 'userInfo',
					data: res.data,
				});
				this.Type = uni.getStorageSync('Type')
				if (res.data.ph_company_vip != 0) {
					this.dqTiem = this.$tools.dateFormatSm(res.data.company_vip * 1000) //会员到期时间
					// 浏览过我

				}
			})
		},
		// 浏览过我
		lookMy() {
			if (uni.getStorageSync('token')) {
				if (this.Type == '0') {
					this.resumeBrowseList()
				} else if (this.Type == '1') {
					this.companyBrowseList()
				}
			}
		},
		//获取收藏列表
		getCollectList() {
			let type = ''
			// 请求这个接口要反转一下
			if (this.Type == '0') {
				type = 1
			} else if (this.Type == '1') {
				type = 0
			}
			user.getCollectList({
				pages: 1,
				type: type
			}).then(res => {
				// 根据身份进行赋值
				if (this.Type == '0') {
					this.data0List[1].value = res.data.total
				} else if (this.Type == '1') {
					this.data1List[1].value = res.data.total
				}
			})
		},
		// 接单查看我的
		resumeBrowseList() {
			user.resumeBrowseList().then(res => {

			})
		},
		// 雇主查看我的
		companyBrowseList() {
			user.companyBrowseList().then(res => {
				this.data1List[2].value = res.data.total
			})
		},
		// 获取浏览记录
		getBrowseList() {
			let type = ''
			// 请求这个接口要反转一下
			if (this.Type == '0') {
				type = 1
			} else if (this.Type == '1') {
				type = 0
			}
			user.getBrowseList({
				pages: 1,
				type: type
			}).then(res => {
				// 根据身份进行赋值
				if (this.Type == '0') {
					this.data0List[2].value = res.data.total
				}
			})
		},
		//跳转
		jump(item) {
			let that = this
			if (item.value == '电话屏蔽中' || item.value == '电话展示中') {
				let title = ''
				if (this.userInfo.is_hide == 1) {
					title = '隐藏电话号码雇主将不能获取到您的电话信息，但不影响在线直聊，您依然可以接收到雇主发来的消息'
				} else {
					title = '是否在接单中显示您的电话号码'

				}
				uni.showModal({
					title: '提示',
					content: title,
					success: (res) => {
						if (res.confirm) {
							resume.editMemberResume({
								edit: 'phone'
							}).then(res => {
								that.getUserInfo()
							})
						}
					}
				})
			} else if (item.value == '接单屏蔽中' || item.value == '接单展示中') {
				let title = ''
				if (this.userInfo.is_hide == 1) {
					title = '点击隐藏接单后，您的所有信息将不会再被雇主搜索到'
				} else {
					title = '是否向雇主展示您的接单'

				}
				uni.showModal({
					title: '提示',
					content: title,
					success: (res) => {
						if (res.confirm) {
							resume.editMemberResume({
								edit: 'resume'
							}).then(res => {
								that.getUserInfo()
							})
						}
					}
				})
			} else if (item.value == '推荐朋友') {

			} else if (item.value == '联系客服') {
				this.$tools.navigate(item.url, item.redirect)
			} else {
				if (item.url == '/pages/user/cut/index') {
					this.$tools.navigate(item.url, item.redirect)
				} else {
					if (uni.getStorageSync('token')) {
						this.$tools.navigate(item.url, item.redirect)
					} else {
						this.$tools.toast('请登录')
						setTimeout(() => {
							this.$tools.navigate('/pages/login/index')
							// uni.reLaunch({
							// 	url: '/pages/login/index'
							// })
						}, 1000)
					}
				}
			}
		},
		//完善资料刷新接单
		jumpCard(item) {
			if (item.url) {
				this.$tools.navigate(item.url, item.redirect)
			} else if (item.title == '刷新接单') {
				user.editMemberResume({
					edit: 'sxjl'
				}).then(res => {
					if (res.msg == '操作失败') {
						this.$tools.toast(res.data)
					}
				})
			}
		},
		// 收藏沟通看过
		dataListBnt(item, index) {
			if (uni.getStorageSync('token')) {
				if (index == 2 && this.userInfo.ph_company_vip == 0) {
					this.$tools.navigate(item.url, item.redirect)
					// this.$tools.toast('暂无权限请开通会员查看')
				} else {
					this.$tools.navigate(item.url, item.redirect)
				}
			} else if (item.value == '沟通过') {
				this.$tools.navigate(item.url, item.redirect)
			} else {
				this.$tools.toast('请登录')
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/login/index'
					})
				}, 1000)
			}
		}
	}
}
